package lagou.model3.test3;

import java.util.*;

public class Test {
    public static void main(String args[]) {
        String[] colors = {"红桃", "黑桃", "梅花", "方块"};
        String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        List<Card> poker = new ArrayList<>(54);
        List<Card> hand=new ArrayList<>(3);
        int order=0;
        //添加扑克牌
        for (String color : colors) {
            for (String number : numbers) {
                switch (number){
                    case "2":
                        order=3;
                        break;
                    case "A":
                        order=4;
                        break;
                    case "K":
                        order=5;
                        break;
                    case "Q":
                        order=6;
                        break;
                    case "J":
                        order=7;
                        break;
                    case "10":
                    case "9":
                    case "8":
                    case "7":
                    case "6":
                    case "5":
                    case "4":
                    case "3":
                        order=18-Integer.parseInt(number);
                        break;

                }
                poker.add(new Card(number, color,order));
            }
        }
        poker.add(new Card("大王","",1));
        poker.add(new Card("小王","",2));
        System.out.println("当前扑克牌有"+poker.size()+"张，分别是："+poker.toString());
        //打乱扑克牌顺序，即洗牌
        Collections.shuffle(poker);
        System.out.println("洗牌后的扑克牌是："+poker.toString());
        //新建三个玩家
        Player player1=new Player("大马猴",new ArrayList<>());
        Player player2=new Player("旭旭宝宝",new ArrayList<>());
        Player player3=new Player("宝哥",new ArrayList<>());

        //发牌
        for(int i=0;i<poker.size();i++){
            if(i>=poker.size()-3){
                hand.add(poker.get(i));
            }
            if(i%3==1){
                player2.getPoker().add(poker.get(i));
            }else if(i%3==2){
                player3.getPoker().add(poker.get(i));
            }else if(i%3==0) {
                player1.getPoker().add(poker.get(i));
            }
        }

        //显示三个玩家摸到的牌
        System.out.println("当前" + player1.getName() + "的牌有：" + player1.getPoker());
        System.out.println("当前" + player2.getName() + "的牌有：" + player2.getPoker());
        System.out.println("当前" + player3.getName() + "的牌有：" + player3.getPoker());
        System.out.println("底牌是：" + hand);

        Comparator<Card> comparator=new Comparator<Card>() {
            @Override
            public int compare(Card card, Card t1) {
                return card.getOrder()-t1.getOrder();
            }
        };
        Collections.sort(player1.getPoker(),comparator);
        Collections.sort(player2.getPoker(),comparator);
        Collections.sort(player3.getPoker(),comparator);
        System.out.println("整理牌后--------------------------------------------------");
        System.out.println("当前" + player1.getName() + "的牌有：" + player1.getPoker());
        System.out.println("当前" + player2.getName() + "的牌有：" + player2.getPoker());
        System.out.println("当前" + player3.getName() + "的牌有：" + player3.getPoker());
        System.out.println("底牌是：" + hand);
    }
}
